<extend name="./base" />
<block name="title">
  <title>上传照片</title>
</block>
 <block name="main"> 


<div style="display:inline-block;margin-top:75px;margin-left:135px;">
<form>

    <div id="queue"></div>
    <input id="file_upload" name="file_upload" type="file" multiple="true">
  </form>
</div>
<div class="photos">
	<?php foreach ($album_photoData as $value):?> 
	<div class='album-item col-md-1' photoid="<?=$value['id']?>" photopath="<?=$value['path']?>">
		
    <button type="buttton"class="btn btn-primary" onclick="szfm(this);return false">设为封面</button>

   <button type="buttton"class="btn btn-primary" onclick="sczp(this);return false">删除照片</button>

		<img src="__PUBLIC__<?php echo $value['path']?>" class="img-thumbnail" >
	</div>
	<?php endforeach;?>
</div>


<script type="text/javascript">
    <?php $timestamp = time();?>
    $(function() {
      $('#file_upload').uploadify({
        'formData'     : {
          'timestamp' : '<?php echo $timestamp;?>',
          'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
        },
        'swf'      : '__PUBLIC__/uploadify.swf',
        'uploader' : "{:U('Xiangce/xiangceUpload',array('album_id'=>$aid))}",
        'buttonText':'上传照片',
        'onUploadSuccess':function(file,data,response){
        	data = eval('('+data+')');
        	if(data.status == '0')
        	{
<<<<<<< HEAD
        
=======

>>>>>>> b1a4ac238f9a1c3ed6d4dedf8f510a27334ccf4c
        		$('.photos').append("<div class='album-item col-md-1' photopath='"+data.path+"' photoid='"+data.id+"'>\
				<button type='buttton'class='btn btn-primary' onclick='szfm(this);return false'>设为封面</button>\
          <button type='buttton'class='btn btn-primary' onclick='sczp(this);return false'>删除照片</button>\
     		<img src='__PUBLIC__"+data.path+"' class='img-thumbnail' >\
				</div>");
        	}
        },
      });
    });
        //删除照片
        function sczp(obj){
     var photoid=$(obj).parent().attr('photoid');
     var photopath=$(obj).parent().attr('photopath');
      $.ajax({
         type:"POST",
         url: "{:U('Xiangce/sczp')}",
         data: {id:photoid,path:photopath},

         success: function(data){
                if(data.status == 0)
                {
                    alert('照片删除成功!');

                   $(obj).parent().remove();
                }
                else if(data['status'] == 1)
                {
                     alert('照片删除失败!');

                };

      }

      });


     }

     function szfm(obj)
     {
      var photoid=$(obj).parent().attr('photoid');
 
         var aid="{:I('get.aid')}";
     
      // console.log(aid);
      $.ajax({
         type:"POST",
         url: "{:U('Xiangce/szfm')}",
         data: {id:photoid ,album_id:aid},

         success: function(data){
                if(data.status == 0)
                {
                    alert('封面设置成功!');

                  
                }else if(data['status'] == 1)
                {
                     alert('封面设置失败!');

                }

            }





      });
     }








  </script>






 </block>